<template>
    <div class="box">
        <div class="banner">
            <div class="layout">
                <div class="button" v-if="detail">
                    <!--                    <el-button type="primary" size="large" @click="toURL" v-show="detail.type!=2 && user.bmanager!= 2">-->
                    <el-button type="primary" size="large" @click="toURL"
                               v-show="detail.type!=2 && getAuth('btnAddSql')">
                        立即申请
                    </el-button>
                    <el-button class="primary" size="large" @click="addCar"
                               v-show="detail.type!=2 && getAuth('btnAddSql')">
                        <!--                               v-show="detail.type!=2 && user.bmanager!= 2">-->
                        加入申请栏
                    </el-button>
                    <!--                    <el-button type="primary" size="large" v-show="detail.type==2 && user.bmanager!= 2"-->
                    <el-button type="primary" size="large" v-show="detail.type==2 && getAuth('btnYxzx')"
                               @click="visible=true">
                        意向咨询
                    </el-button>
                </div>
            </div>
        </div>
        <div class="details" v-loading="loading">
            <div class="tabs">
                <div class="layout">
                    <span class="mr20" :class="{active: show}" @click="cutTab">产品介绍</span>
                    <span :class="{active: !show}" @click="cutTab">文档与资源</span>
                </div>
            </div>
            <div class="introduce layout" v-if="show&&detail">
                <div class="title">产品介绍</div>
                <div class="pd-box white-block" v-for="(item,index) in detail.resIntroVO.moduleList" :key="index">
                    <p>{{item.content}}</p>
                    <img :src="item.imgUrl" alt="">
                </div>
            </div>
            <div class="document layout" v-if="!show&&detail">
                <div class="title">文档列表</div>
                <div class="pd-box  white-block table">
                    <table-example :data="detail.docList" :tableColumn="header" :slotColumns="slotColumns"
                                   class="mt20 ">
                        <template slot="name" slot-scope="scope">
                            <i class="el-icon-document" style="font-size: .2rem"></i>
                            <span>{{scope.row.name}}</span>
                        </template>
                        <template slot="operation" slot-scope="scope">
                            <el-link type="primary" :underline="false" :href="scope.row.fileUrl" target="_blank">
                                <i class="el-icon-download"
                                   style="color: #4995F4;font-size: .18rem;vertical-align: middle;"></i>
                                下载
                            </el-link>
                        </template>
                    </table-example>
                </div>
            </div>
        </div>
        <!--        <div class="foot" v-if="detail && user.bmanager!= 2">-->
        <div class="foot" v-if="detail && (getAuth('btnYxzx') || getAuth('btnAddSql'))">
            <div class="text-right layout">
                <el-button class="btn btn-t" @click="addCar" v-show="detail.type!=2" v-if="getAuth('btnAddSql')">加入申请栏
                </el-button>
                <el-button type="primary" class="btn " @click="toURL" v-show="detail.type!=2"
                           v-if="getAuth('btnAddSql')">立即申请
                </el-button>
                <el-button type="primary" class="btn " v-show="detail.type==2" v-if="getAuth('btnYxzx')"
                           @click="visible=true">意向咨询
                </el-button>
            </div>
        </div>
        <dialog-msk :show.sync="visible" ref="dialog" :title="'意向咨询'">
            <div slot="footer" class="text-center">
                    <span slot="footer">
                        <el-button @click="close">取消</el-button>
                        <el-button type="primary" @click="save">确定</el-button>
                    </span>
            </div>
            <div>
                <el-input
                    type="textarea"
                    placeholder="请补充说明您的需求,200字以内"
                    v-model="content"
                    maxlength="200"
                    show-word-limit
                    :autosize="{ minRows: 4, maxRows: 4}"
                >
                </el-input>
            </div>
        </dialog-msk>
    </div>
</template>

<script>
    import tableExample from '../../components/table'
    import page from '../../components/pagination'
    import dialogMsk from '../../components/dialog'
    import {mapGetters} from 'vuex'

    export default {
        data() {
            return {
                detail: null,
                activeName: 'first',
                header: [
                    {
                        prop: 'name',
                        label: '文档',
                        minWidth: '25%',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'fileSize',
                        label: '大小',
                        minWidth: '25%',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'createTime',
                        label: '上传时间',
                        minWidth: '25%',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'operation',
                        label: '操作',
                        align: 'center',
                        minWidth: '25%'
                    }
                ],
                slotColumns: ['operation', 'name'],
                data: null,
                loading: false,
                index: 1,
                visible: false,
                text: '',
                content: '',
                show: true,
                id: ''
            }
        },
        mounted() {
            this.id = this.$route.params.id
            this.getData()
        },
        computed: {
            ...mapGetters([
                'user'
            ])
        },
        methods: {
            cutTab() {
                this.show = !this.show
                this.$method.updateView(true)
            },
            save() {
                let content = this.content
                this.close()
                this.loading = true
                this.$http.post('/gsOrder/addIntention', {
                    content: content,
                    resId: this.detail.id
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                        this.$alert('咨询提交成功', '提示', {
                            confirmButtonText: '确定',
                            closeOnClickModal: true,
                            callback: action => {
                            },
                            closeOnPressEscape: true
                        })
                    }
                }).catch(() => {
                    this.loading = false
                })
            },
            close() {
                this.content = ''
                this.visible = false
            },
            handleClick(tab, event) {
                this.$nextTick(() => {
                    this.$method.updateView()
                })
            },
            getData(id) {
                this.loading = true
                this.$http.get('/gsRes/getResById', {
                    id: this.id
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                        this.detail = result.data
                        this.$method.updateView()
                    }
                }).catch(() => {
                    this.loading = false
                })
            },
            toURL() {
                this.$router.push({
                    path: '/spm/applicationSubmit',
                    query: {
                        resId: this.detail.id
                    }
                })
            },
            addCar() {
                this.loading = true
                this.$http.post('/gsOrder/addOrderItem', {
                    resId: this.id
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                    }
                }).catch(() => {
                    this.loading = false
                })
            },
            getAuth(auth) {
                return this.user && this.user.authTree && this.user.authTree[auth]
            }
        },
        components: {
            tableExample,
            page,
            dialogMsk
        }
    }
</script>
<style scoped lang="less">
    .box {
        padding-bottom: 1rem !important;

        .banner {
            height: 4.2rem;
            background-image: url('../../../static/images/pdbanner.png');
            background-position: center;
            background-size: contain;
            background-repeat: no-repeat;
            position: relative;

            > .layout {
                position: relative;
                height: 100%;

                .button {
                    position: absolute;
                    bottom: 1rem;
                    left: .4rem;

                    .button-l {
                        color: #00003E;
                        background-color: #4995F4;
                        width: 1.4rem;
                        height: .5rem;
                        border-radius: .05rem;
                        border-color: #4995F4;
                    }

                    .button-r {
                        width: 1.4rem;
                        height: .5rem;
                        border-radius: .05rem;
                    }
                }
            }
        }

        .details {
            .tabs {
                background-color: #fff;
                height: .7rem;
                line-height: .7rem;

                span {
                    display: inline-block;
                    cursor: pointer;
                    font-size: .16rem;

                    &.active {
                        font-weight: bold;
                        font-size: .18rem;
                    }
                }
            }

            .introduce, .document {
                .title {
                    padding: .4rem 0;
                    text-align: center;
                    font-size: .2rem;
                }
            }

            .pd-box {
                text-align: center;
                margin-bottom: .2rem;

                &:last-child {
                    margin-bottom: 0;
                }

                p {
                    font-size: 0.14rem;
                    /*padding-top: 0.7rem;*/
                }

                img {
                    margin-left: 2.47rem;
                    margin-top: 0.8rem;
                }

                .page {
                    /*position: absolute;*/
                    margin-top: 0.7rem;
                    /*right: 0.3rem;*/
                    /*bottom: 0.86rem;*/
                }

                .button {
                    border: none;
                    background-color: #fff;
                    color: #1497fc;
                }
            }
        }
    }

    .foot {
        width: 100%;
        height: 0.8rem;
        background-color: #fff;
        box-shadow: 0.03rem 0 0.05rem rgba(0, 0, 0, .1);
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 10;

        > * {
            display: flex;
            height: 100%;
            align-items: center;
            justify-content: flex-end;
        }
    }
</style>
